import { director } from "cc";
import { GameEvent } from "./GameEvent";
import protocol from "../proto/protoExt";

class UserInfo {

    private fishs: protocol.new_world.shared.v1.IImmortalDetail[] = [];


    /**获取鱼列表 */
    getFishs() {
        return this.fishs
    }
    /**获取鱼根据id */
    getFish(id: string) {
        return this.fishs.find(item => item.fish?.id == id)
    }
    /**设置鱼的列表 */
    setFishs(fishs: protocol.new_world.shared.v1.IImmortalDetail[]) {
        if (fishs) {
            this.fishs = fishs
        }
    }
    /**更新鱼 */
    updateFish(fish: protocol.new_world.shared.v1.IImmortalDetail) {
        let myfish = this.fishs.find(item => item.fish?.id == fish.fish?.id)
        if (myfish) {
            this.fishs[this.fishs.indexOf(myfish)] = fish
            director.emit(GameEvent.updateFish, fish)
        }
    }
    /**添加鱼 */
    addFish(fish: protocol.new_world.shared.v1.IImmortalDetail) {
        this.fishs.push(fish)
        director.emit(GameEvent.addFish, fish)
    }
    /**炼化鱼 */
    removeFishByid(id: string) {
        let fish = this.fishs.find(item => item.fish?.id == id)
        if (fish) {
            this.fishs.splice(this.fishs.indexOf(fish), 1)
            director.emit(GameEvent.removeFish, fish)
        }

    }
}
export const userinfo = new UserInfo()